package main

import (
	"database/sql"
	"log"

	_ "github.com/mattn/go-sqlite3"
)

type User struct {
	Name string `geeorm:"PRIMARY KEY"`
}

func main() {
	db, _ := sql.Open("sqlite3", "testgee.db")
	defer func() { _ = db.Close() }()
	_, _ = db.Exec("DROP TABLE IF EXISTS User;")
	_, _ = db.Exec("CREATE TABLE User(Name text);")
	_, err := db.Exec("INSERT INTO User(`Name`) values (?), (?)", "Tom", "Sam")
	if err != nil {
		panic(err)
	}

	//affected, _ := result.RowsAffected()
	//log.Println(affected)

	//ok
	row := db.QueryRow("SELECT Name FROM User LIMIT 1")
	var name string
	if err := row.Scan(&name); err == nil {
		log.Println(name)
	}

	//User 多条
	var users []string
	rows, _ := db.Query("SELECT Name FROM User LIMIT 2")
	for rows.Next() {
		var user string
		if err := rows.Scan(&user); err == nil {
			users = append(users, user)
		}
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}
	log.Println(users)
}
